/**
 * Copyright © 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.flowable.CheckCycle.Service;

import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.flowable.CheckCycle.entity.*;
import com.jeeplus.modules.flowable.CheckCycle.mapper.BasicdataCheckFormCycleMapper;
import com.jeeplus.modules.flowable.CheckCycle.mapper.BasicdataCheckCycleMapper;
import com.jeeplus.modules.flowable.myListenerService.entity.AbnormalProcessANDRepair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.UUID;

/**
 * 设备点检标准Service
 * @author 王志鹏
 * @version 2020-09-25
 */
@Transactional(readOnly = true)
@Service
public class BasicdataCheckStandardMainCycleService extends CrudService<BasicdataCheckCycleMapper, BasicdataCheckStandardMainCycle> {
	@Autowired
	private  BasicdataCheckCycleMapper basicdataCheckCycleMapper;

	@Autowired
	private BasicdataCheckFormCycleMapper basicdataCheckFormMapper;

	@Transactional(readOnly = false)
	public BasicdataCheckStandardMainCycle getid(String id) {
		BasicdataCheckStandardMainCycle basicdataCheckStandardMain = super.get(id);
		basicdataCheckStandardMain.setBasicdataCheckFormList(basicdataCheckFormMapper.findList(new BasicdataCheckFormCylce(basicdataCheckStandardMain)));
		return basicdataCheckStandardMain;
	}

	@Transactional(readOnly = false)
	public String saveID(BasicdataCheckStandardMainCycle basicdataCheckStandardMain) {
		UUID uid = UUID.randomUUID();
		String idstr = uid.toString().replace("-", "");
		basicdataCheckStandardMain.setId(idstr);
		basicdataCheckStandardMain.setIsNewRecord(true);
		super.save(basicdataCheckStandardMain);
		for (BasicdataCheckFormCylce basicdataCheckForm : basicdataCheckStandardMain.getBasicdataCheckFormList()){
			if (basicdataCheckForm.getId() == null){
				continue;
			}
			if (BasicdataCheckFormCylce.DEL_FLAG_NORMAL.equals(basicdataCheckForm.getDelFlag())){
					basicdataCheckForm.setCheckName(basicdataCheckStandardMain);
					basicdataCheckForm.preInsert();
					basicdataCheckFormMapper.insert(basicdataCheckForm);
			}else{
				basicdataCheckFormMapper.delete(basicdataCheckForm);
			}
		}
		return basicdataCheckStandardMain.getId();
	}
	@Transactional(readOnly = false)
	public CheckStandardCheck getbasicdataCheckStandardMainCycle(String id) {
		CheckStandardCheck checkStandardcycle = basicdataCheckCycleMapper.getbasicdataCheckStandardMainCycle(id);
		return checkStandardcycle;
	}
	@Transactional(readOnly = false)
	public AbnormalProcessANDRepair getCheckStandardAbnormalCycle(String id) {
		AbnormalProcessANDRepair checkStandardAbnormalCycle = basicdataCheckCycleMapper.getCheckStandardAbnormalCycle(id);
		return checkStandardAbnormalCycle;
	}

	public RepairTaskDistributionProcessflowable getrepairTaskDistributionProcessJoins(String id){
		return basicdataCheckCycleMapper.getrepairTaskDistributionProcessJoins(id);
	}

}